package strategies;

import agents.AverageUtility;
import plots.Plot;


/**
 * Associates a plot with a farmed ratio and an utility.
 */
public class PlotTarget implements Cloneable, Comparable<PlotTarget> {
	
	public Plot plot; // harvested plot
	public int target; // target quantity to be harvested from the plot
	public AverageUtility averageUtility; // the utility for this plot/target association
	
	
	public PlotTarget(Plot plot) {
		this(plot, 0);
	}
	
	public PlotTarget(Plot plot, int target) {
		this.plot = plot;
		this.target = target;
		this.averageUtility = new AverageUtility();
	}
	
	
	@Override
	public PlotTarget clone(){
		return new PlotTarget(plot, target);
	}
	
	@Override
	public String toString() {
		return new StringBuilder().append(target).append(':').append(averageUtility)
				.append('@').append(plot.hashCode()).toString();
	}
	
	@Override
	public boolean equals(Object o){
		if (!(o instanceof PlotTarget))
			return false;
		PlotTarget plT = (PlotTarget) o;
		if (this.plot != plT.plot || this.target != plT.target)
			return false;
		return true;
	}


	@Override
	public int compareTo(PlotTarget o) {
		double ratio = averageUtility.getAverageUtility() - o.averageUtility.getAverageUtility();		
		return ratio<0?-1:(ratio==0?0:1);
	}
}
